package com.hyh.springcloud.controller;

import com.hyh.springcloud.entity.Payment;
import com.hyh.springcloud.result.AjaxResult;
import com.hyh.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Summerday
 */

@Slf4j
@RestController
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment")
    public AjaxResult create(@RequestBody Payment payment) {
        int result = paymentService.create(payment);
        log.info("插入结果 : " + result);
        return result > 0 ? AjaxResult.ok() : AjaxResult.error();
    }


    @GetMapping("/payment/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        log.info("端口 : {} , 获得结果 : {}", serverPort, payment);
        return payment == null ? AjaxResult.error() : AjaxResult.ok(serverPort,payment);
    }

    @GetMapping("/payment/lb")
    public String getServerPortLb(){
        return serverPort;
    }
}
